package net.ebakker.feededitor.database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.annotation.CheckForNull;

import net.ebakker.feededitor.Preferences;

public class PostgresConnector {

	@CheckForNull
	public static Connection connect(Preferences preferences) throws ClassNotFoundException {
		Class.forName("org.postgresql.Driver");

		String url =
				"jdbc:postgresql://" + preferences.getPgHost() + ":" + preferences.getPgPort()
						+ "/ttrss";

		Connection connection = null;

		try {
			connection =
					DriverManager.getConnection(url, preferences.getPgUsername(),
							preferences.getPgPassword());
			return connection;
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return null;
	}
}
